import time

import matplotlib.pylab as plt

from alg import Solution
from gen import test_data

solution = Solution()
simple_running_times = []
normal_running_times = []
best_running_times = []
data_size = [i for i in range(10,12000,1000)]

def count_main():
    nums=test_data['nums']
    lower=test_data['lower']
    upper=test_data['upper']
    solution=Solution()
    print("nums={}".format(nums))
    print("lower={}".format(lower))
    print("upper={}".format(upper))
    print("result={}".format(solution.count_range_sum(nums, lower, upper)))

def simple_test(nums, k):
    start_time = time.time()
    solution.lengthOfLIS_simple(nums, k)
    end_time = time.time()
    r_time = end_time - start_time
    simple_running_times.append(r_time)
    print(f"simple running in{r_time}")


def normal_test(nums, k):
    start_time = time.time()
    solution.lengthOfLIS_normal(nums, k)
    end_time = time.time()
    r_time = end_time - start_time
    normal_running_times.append(r_time)
    print(f"normal running in{r_time}")


def best_test(nums, k):
    start_time = time.time()
    solution.lengthOfLIS_best(nums, k)
    end_time = time.time()
    r_time = end_time - start_time
    best_running_times.append(r_time)
    print(f"best running in{r_time}")


def lengthOfLIS_main():
    for data in test_data["lengthOfLIS"]:
        simple_test(data[0], data[1])
        normal_test(data[0], data[1])
        best_test(data[0], data[1])

    plt.plot(data_size,simple_running_times, label="simple_running_times")
    plt.plot(data_size,normal_running_times, label="normal_running_times")
    plt.plot(data_size,best_running_times, label="best_running_times")
    plt.xlabel("Data Set Size")
    plt.ylabel("Time (in seconds)")
    plt.title("Solving times")
    plt.legend()
    plt.show()

    plt.figure()
    plt.plot(data_size,normal_running_times, label="normal_running_times")
    plt.plot(data_size,best_running_times, label="best_running_times")
    plt.xlabel("Data Set Size")
    plt.ylabel("Time (in seconds)")
    plt.title("Solving times")
    plt.legend()
    plt.show()

def getSkyline_main():
    object = Solution()
    # print(object.getSkyline(buildings=test_data["天际线 输入样例1"]))
    # print(object.getSkyline(buildings=test_data["天际线 输入样例2"]))
    print(object.getSkyline(buildings=test_data["天际线随机数据"]))
    pass

def median_main():
    data = test_data['median']
    print("nums1: {}".format(data[0]))
    print("nums2: {}\n".format(data[1]))
    print("median: {}".format(solution.find_median_sorted_arrays(data[0], data[1])))

def madion_main():
    data = test_data['sort_lists']
    solution = Solution()
    print("lists: ")
    for i in range(len(data)):
        curr = data[i]
        while curr:
            print(curr.val, end=' ')
            curr = curr.next

    print("sort: ")
    List=solution.mergeKLists(data)
    curr = List
    while curr:
        print(curr.val, end=' ')
        curr = curr.next

if __name__ == '__main__':
    lengthOfLIS_main()
    getSkyline_main()
    median_main()
    madion_main()
    count_main()

